<template>
  <!-- 一条文章单元格 -->
<div>
    <van-cell>
    <!-- 标题区域的插槽 -->
    <template #title>
      <div class="title-box">
        <!-- 标题 -->
        <span>{{artObj.title}}</span>
        <!-- 单图 -->
        <!-- <img v-if="artObj.cover.type === 1" class="thumb"  :src="artObj.cover.images[0]" alt=""> -->
        <van-image v-if="artObj.cover.type === 1" class="thumb"  :src="artObj.cover.images[0]">
          <template v-slot:error>加载失败</template>
        </van-image>
      </div >
       <!-- 多图 -->
     <div class="thumb-box" v-if="artObj.cover.type>1">
      <!-- <img v-for="(imgURL,index) in artObj.cover.images"
      :key="index"
      class="thumb"
      :src="imgURL"
      alt="图片丢失了"> -->

      <van-image  v-for="(imgURL,index) in artObj.cover.images"
      :key="index"
      class="thumb"
      :src="imgURL">
        <template v-slot:error>加载失败</template>
      </van-image>
     </div>
    </template>
    <!-- label 区域的插槽 -->
    <template #label>
      <div class="label-box">
        <div>
          <span>{{artObj.aut_name}}</span>
          <span>{{artObj.comm_count}}评论</span>
          <span>{{formatTime(artObj.pubdate)}}个月前</span>
        </div>
        <!-- 反馈按钮 -->
        <van-icon name="cross" @click.stop="show =true "  v-if="isShow" />
      </div>
    </template>
  </van-cell>
   <!-- 反馈面板
    <! get-container="body" 更改挂载点到body  在cell里多出来的部分会被隐藏 把挂载点设到body这样就不会被 cell里的overflow: hidden影响 -->
   <van-action-sheet v-model="show"
    :actions="actions"
     :cancel-text="bottomText"
     @select="onSelect"
     @cancel="cancelFn"
     @close='closeFn'

      get-container="body"/>
</div>

</template>

<script>
import { timeAgo } from '@/utils/date.js'
import { firstActions, secondActions } from '@/api/report.js'
export default {
  props: {
    artObj: Object, // 文章对象
    isShow: {
      type: Boolean,
      default: true// 例如首页的地方我不想去改了，首页肯定没传isShow进来，所以默认显示，
    }
  },
  data () {
    return {
      show: false,
      actions: firstActions,
      bottomText: '取消'
    }
  },
  methods: {
    formatTime: timeAgo, // 函数体是timeAgo
    onSelect (actions, item) {
      // 默认情况下点击选项时不会自动收起
      // 可以通过 close-on-click-action 属性开启自动收起
      // this.show = false
      if (actions.name === '反馈垃圾内容') {
        this.actions = secondActions
        this.bottomText = '返回'
      } else if (actions.name === '不感兴趣') {
        this.$emit('disLikeEV', this.artObj.art_id)
        this.show = false// 无论成功/失败反馈面板隐藏
      } else { // 二级反馈选项
        this.$emit('reportEV', this.artObj.art_id, actions.value)
        this.show = false
      }
    },
    // 底部按钮点击事件
    cancelFn () {
      if (this.bottomText === '返回') {
        this.actions = firstActions
        this.bottomText = '取消'
        this.show = true// 强制让它回来
      }
    },
    // 关闭面板时触发的事件  关闭面板将数组值和按钮文字改回一级标题
    closeFn () {
      this.actions = firstActions
      this.bottomText = '取消'
    }
  }
}
</script>

<style scoped lang="less">
/* 标题样式 */
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* label描述样式 */
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 文章信息span */
.label-box span{
    margin: 0 3px;
    &:first-child{
        margin-left: 0;
    }
}
/* 图片的样式, 矩形黄金比例：0.618 */
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

/* 三图, 图片容器 */
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
